<?php

require_once '../data/connect.class.php';
$connect = new Connect("localhost","root","","email");
$param = $_POST['param'];

if (isset($param)) {
	
	if ($param == 'smtplist') {
		$querySql="select id,name,from_addr,host,port,user_name,status from admin_smtp_server;";
		$resultSet = $connect->execute($querySql);
		echo "<div class='page_user_row'>";
		echo "  <div class='page_smtp_content'>";
		echo "     <strong>名字</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content' style='width: 140px;'>";
		echo "    <strong>邮件地址</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>主机地址</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>端口</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>用户名</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>状态</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>操作</strong>";
		echo "  </div>";
		echo "</div>";
		foreach($resultSet as $res) {
			echo "<div class='page_user_row'>";
			echo "  <div class='page_smtp_content'>";
			echo $res['name'];
			echo "  </div>";
			echo "  <div class='page_smtp_content' style='width: 140px;'>";
			echo $res['from_addr'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['host'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['port'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['user_name'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['status']?"激活":"禁用";
			echo "  </div>";
			echo "  <div class='page_smtp_content' onclick='delSmtp(\"";
			echo $res['id'];
			echo "\")' style='cursor:pointer;'>";
			echo "删除";
			echo "  </div>";
			echo "</div>";
		}
	}
	if ($param == 'addSmtp') {
		echo "<label>名字:</label>"; 
		echo "<input type='text' id='smtp_name' value='' /><br/>"; 
		echo "<label>邮件地址:</label>"; 
		echo "<input type='text' id='from_addr' value='' /><br/>"; 
		echo "<label>主机地址:</label>"; 
		echo "<input type='text' id='smtp_host' value='' /><br/>"; 
		echo "<label>端口:</label>"; 
		echo "<input type='text' id='smtp_port' value='' /><br/>"; 
		echo "<label>用户名:</label>"; 
		echo "<input type='text' id='smtp_user_name' value='' /><br/>"; 
		echo "<label>密码:</label>"; 
		echo "<input type='text' id='smtp_password' value='' /><br/>"; 
		echo "<label>状态:</label>"; 
        echo "<select id='smtp_status'>";
        echo "<option value='1' selected='selected'>激活</option>";
        echo "<option value='0'>禁用</option>";
        echo "</select><br/>";
		
		echo "<div onclick='addSmtp()' style='cursor:pointer;'>确定</div>";
	}
	if ($param == 'editSmtp') {
	$querySql="select id,name,from_addr,host,port,user_name,password,status from admin_smtp_server;";
		$resultSet = $connect->execute($querySql);
		echo "<div class='page_user_row'>";
		echo "  <div class='page_smtp_content'>";
		echo "     <strong>名字</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content' style='width: 140px;'>";
		echo "    <strong>邮件地址</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>主机地址</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>端口</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>用户名</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>状态</strong>";
		echo "  </div>";
		echo "  <div class='page_smtp_content'>";
		echo "    <strong>操作</strong>";
		echo "  </div>";
		echo "</div>";
		foreach($resultSet as $res) {
			echo "<div class='page_user_row'>";
			echo "  <div class='page_smtp_content'>";
			echo $res['name'];
			echo "  </div>";
			echo "  <div class='page_smtp_content' style='width: 140px;'>";
			echo $res['from_addr'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['host'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['port'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['user_name'];
			echo "  </div>";
			echo "  <div class='page_smtp_content'>";
			echo $res['status']?"激活":"禁用";
			echo "  </div>";
			echo "  <div class='page_smtp_content' onclick='editSmtp(";
			echo $res['id'];
			echo ",\"";
			echo $res['name'];
			echo "\",\"";
			echo $res['from_addr'];
			echo "\",\"";
			echo $res['host'];
			echo "\",";
			echo $res['port'];
			echo ",\"";
			echo $res['user_name'];
			echo "\",\"";
			echo $res['password'];
			echo "\",";
			echo $res['status'];
			echo ")' style='cursor:pointer;'>";
			echo "修改";
			echo "  </div>";
			echo "</div>";
		}
	}
}

?>